<%@ include file="header.jsp" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>


<script type="text/javascript">

	//alert("Creating chart...");

	var catsArray = new Array();
	var dataArray = new Array();
	var companiesArray = new Array();
	
	<c:forEach items="${preselectedCompanies}" var="company" varStatus="rowCounter">
		catsArray.push('${rowCounter.count}');
		dataArray.push(${fn:length(company.votes)});
		companiesArray.push('${company.companyInfo.name}');
	</c:forEach>

	
	$(document).ready(function() {

		$("#advice ").tooltip();
		
		
		chart = new Highcharts.Chart({
			chart: {
				renderTo: 'container',
				defaultSeriesType: 'column'
			},
			title: {
				text: "<fmt:message key='home.chart.title'/>"
			},
			xAxis: {
				title: {
					text: '<fmt:message key="home.chart.xAxis.title"/>'
				},
				categories: catsArray
			},
			yAxis: {
				min: 0,
				title: {
					text: '<fmt:message key="home.chart.yAxis.title"/>'
				}
			},
			legend: {
				style: {
					left: 'auto',
					bottom: 'auto',
					right: '70px',
					top: '35px'
				},
				backgroundColor: '#FFFFFF',
				borderColor: '#CCC',
				borderWidth: 1,
				shadow: false
			},
			tooltip: {
				formatter: function() {
					return '<b>'+ companiesArray[this.x-1] +'</b><br/>'+
						 this.series.name +': '+ this.y;
				}
			},
			plotOptions: {
				column: {
					stacking: 'normal'
				}
			},
		    series: [{
				name: '<fmt:message key="home.chart.series.name"/>',
				data: dataArray//[5, 3, 4, 7, 2]
			}]
		});
		
		
	});

	function confirmSubmit(email) {
		var agree=confirm("Are you sure you wish to continue removing votes from " + email + "?");
		if (agree)
			return true ;
		else
			return false ;
	}

	
</script>
			
			<div class="conten_dcha">
			
				<h3>Votes manager</h3>
				
				<BR/>
				<p class="total_votes" >Total Votes: ${totalvotes}</p>
					<!-- 3. Add the container -->
				<div class="conten_legend">
				Legend:
				
				<c:forEach items="${preselectedCompanies}" var="company" varStatus="rowCounter">
					<ul>
						<li>${rowCounter.count}. <strong>${company.companyInfo.name}</strong></li>
						
					</ul>
					
				</c:forEach>
				</div>
				<div id="container" style="width: 230px; height: 200px; float:left;"></div>
				
                <p class="total_votes">List of votes</p>
               
                <div class="lst_resultados">
                <ul>
                <c:if test="${previous == 1}">
                	<li><a href="<c:url value='/dashboard/votes-manager/${previousPage}'/>"><< Previous </a></li>
                </c:if>
                <c:if test="${next == 1}">
                	<li><a href="<c:url value='/dashboard/votes-manager/${nextPage}'/>">Next >></a></li>
                </c:if>
                </ul>
                </div>
                
                <table class="lst_practices tablesorter" cellspacing="1" summary="<fmt:message key='company.list.table.title'/>">
                  <caption>
                    <fmt:message key='company.list.table.title'/>
                  </caption>
			      <thead>
                    <tr>
                      <th scope="col" >Who voted</th>             
                      <th scope="col">Votes</th>  
                      <th scope="col">Actions</th>
                    </tr>
                  </thead>
                  <tbody>
                  <c:forEach var="item" items="${votes}">
                   
                  		<tr >
                  		<td>                  		
      						${item.key}
      					</td>
                      	         	
                      	<td>
                      		<a id="advice">See it</a>
                      		
                      		<div class="tooltip">
								Votes of ${item.key} <br/>
								<img src="<c:url value='/static/img/interfaz/eye.png'/>" alt="Flying screens" style="float:left;margin:5px 15px 20px 0" />
								<table style="margin:0">
								<c:forEach var="vote" items="${item.value}">
								<tr>
									<td>${companiesMap[vote.companyId].companyInfo.name}</td>	
								</tr>
								</c:forEach>
							</table>	
							</div>
							
                      		
                      	</td>
                      	<td>
                      	
                      		<form action="<c:url value='/dashboard/votes/remove'/>" method="POST">
                      			<input type="hidden" name="email" value="${item.key}"/>
                      			<input type="submit" title="Delete" value="Delete" onClick="return confirmSubmit('${item.key}')"/>
                      		</form>
                      	
                    
                      	</td>
                      </tr>
                  	</c:forEach>
                  </tbody>
                </table>
                
                
			</div>
<%@ include file="footer.jsp" %>